package com.zeng.sboot.amqp.consumer.config.amqp;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zeng.sboot.demo.amqp.config.RabbitmqConfig;
import com.zeng.sboot.demo.amqp.domain.Order;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class EmailSmsReceiver {

    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receiveEmail(Order msg, Message message, Channel channel,@Headers Map<String, Object> headers) throws Exception {
        System.out.println(msg);
        Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
        // 手工 ACK
        channel.basicAck(deliveryTag, false);
    }

    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_SMS})
    public void receiveSms(Order msg, Message message, Channel channel,@Headers Map<String, Object> headers) throws Exception {
        System.out.println(msg);
        Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
        // 手工 ACK
        channel.basicAck(deliveryTag, false);
    }


}
